# Load packages
librarian::shelf(dplyr, haven, tidyr, quiet = TRUE)

# Load the Stata data file
data <- read_dta("Data/Meta/druckman_2023.dta")

# Drop "correction and uncertainty" and "correction and competition" conditions
data <- data %>%
    subset(condition <= 2)

# Recode condition variable
data$condition <- data$condition - 1

# Creating the variable support for partisan violence (SPV)
data$viol <- data %>%
    select("threat", "harass", "violgoals", "violelec") %>%
    rowMeans(na.rm = TRUE)

# Creating the variable support for undemocratic practices (SUP)
data$demnorms <- data %>%
    select("ban", "court", "freeze", "voting", "laws", "viollaws", "const") %>%
    rowMeans(na.rm = TRUE)

# Get ranges
max(data$viol) - min(data$viol)
max(data$demnorms) - min(data$demnorms)

# Run t-tests
lm(viol ~ condition, data = data) %>% summary()
lm(demnorms ~ condition, data = data) %>% summary()
